//
//  MovieViewController.m
//  UI_豆瓣扩展
//
//  Created by dllo on 15/11/8.
//  Copyright © 2015年 张磊. All rights reserved.
//

#import "MovieViewController.h"
#import "MovieListViewController.h"
#import "MovieSecondViewController.h"
@interface MovieViewController ()

@property (nonatomic, retain)MovieListViewController *movieLVC;
@property (nonatomic, retain)MovieSecondViewController *movieSVC;
@property (nonatomic, retain)UICollectionView *collectionV;
@property (nonatomic, assign)BOOL isSelect;

@end

@implementation MovieViewController
- (void)dealloc
{
    [_movieLVC release];
    [_movieSVC release];
    [_collectionV release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor purpleColor];
    self.navigationItem.title = @"电影";
    
    
    self.movieSVC = [[MovieSecondViewController alloc]init];
    [self addChildViewController:self.movieSVC];
    [self.view addSubview:self.movieSVC.view];
    [self.movieSVC release];
    
    self.movieLVC = [[MovieListViewController alloc]init];
    [self addChildViewController:self.movieLVC];
    [self.view addSubview:self.movieLVC.view];
    [self.movieLVC release];
    
    
    
    UIImage *image = [UIImage imageNamed:@"btn_nav_collection@2x.png"];
    image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithImage:image style:UIBarButtonItemStylePlain target:self action:@selector(rightBar:)];
    
    
    self.isSelect = YES;
    
    
    
    
}

- (void)rightBar:(UIBarButtonItem *)bar
{
    if (self.isSelect == 1) {
        [UIView transitionFromView:self.movieLVC.view toView:self.movieSVC.view duration:0.5 options:UIViewAnimationOptionTransitionFlipFromLeft completion:^(BOOL finished) {
            
            UIImage *image = [UIImage imageNamed:@"btn_nav_list@2x.png"];
            
            //取消图片渲染
            image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
            self.navigationItem.rightBarButtonItem.image = image;
            
        }];

            }else{
        [UIView transitionFromView:self.movieSVC.view toView:self.movieLVC.view duration:0.5 options:UIViewAnimationOptionTransitionFlipFromRight completion:^(BOOL finished) {
            
            UIImage *image = [UIImage imageNamed:@"btn_nav_collection@2x.png"];
            
            //取消图片渲染
            image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
            self.navigationItem.rightBarButtonItem.image = image;
        }];

    }
    self.isSelect = !self.isSelect;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
